home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / mozilla-firefox / include / nkcache / nsCacheService.h next >
C/C++ Source or Header  |  2006-05-08  |  9KB  |  252 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  2.  *
  3.  * ***** BEGIN LICENSE BLOCK *****
  4.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  5.  *
  6.  * The contents of this file are subject to the Mozilla Public License Version
  7.  * 1.1 (the "License"); you may not use this file except in compliance with
  8.  * the License. You may obtain a copy of the License at
  9.  * http://www.mozilla.org/MPL/
  10.  *
  11.  * Software distributed under the License is distributed on an "AS IS" basis,
  12.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  13.  * for the specific language governing rights and limitations under the
  14.  * License.
  15.  *
  16.  * The Original Code is nsCacheService.h, released
  17.  * February 10, 2001.
  18.  *
  19.  * The Initial Developer of the Original Code is
  20.  * Netscape Communications Corporation.
  21.  * Portions created by the Initial Developer are Copyright (C) 2001
  22.  * the Initial Developer. All Rights Reserved.
  23.  *
  24.  * Contributor(s):
  25.  *   Gordon Sheridan  <gordon@netscape.com>
  26.  *   Patrick C. Beard <beard@netscape.com>
  27.  *   Darin Fisher     <darin@netscape.com>
  28.  *
  29.  * Alternatively, the contents of this file may be used under the terms of
  30.  * either the GNU General Public License Version 2 or later (the "GPL"), or
  31.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  32.  * in which case the provisions of the GPL or the LGPL are applicable instead
  33.  * of those above. If you wish to allow use of your version of this file only
  34.  * under the terms of either the GPL or the LGPL, and not to allow others to
  35.  * use your version of this file under the terms of the MPL, indicate your
  36.  * decision by deleting the provisions above and replace them with the notice
  37.  * and other provisions required by the GPL or the LGPL. If you do not delete
  38.  * the provisions above, a recipient may use your version of this file under
  39.  * the terms of any one of the MPL, the GPL or the LGPL.
  40.  *
  41.  * ***** END LICENSE BLOCK ***** */
  42.  
  43.  
  44. #ifndef _nsCacheService_h_
  45. #define _nsCacheService_h_
  46.  
  47. #include "nsICacheService.h"
  48. #include "nsCacheSession.h"
  49. #include "nsCacheDevice.h"
  50. #include "nsCacheEntry.h"
  51.  
  52. #include "nspr.h"
  53. #include "nsIObserver.h"
  54. #include "nsString.h"
  55. #include "nsIEventQueueService.h"
  56. #include "nsProxiedService.h"
  57.  
  58. class nsCacheRequest;
  59. class nsCacheProfilePrefObserver;
  60. class nsDiskCacheDevice;
  61. class nsMemoryCacheDevice;
  62.  
  63.  
  64. /******************************************************************************
  65.  *  nsCacheService
  66.  ******************************************************************************/
  67.  
  68. class nsCacheService : public nsICacheService
  69. {
  70. public:
  71.     NS_DECL_ISUPPORTS
  72.     NS_DECL_NSICACHESERVICE
  73.     
  74.     nsCacheService();
  75.     virtual ~nsCacheService();
  76.  
  77.     // Define a Create method to be used with a factory:
  78.     static NS_METHOD
  79.     Create(nsISupports* outer, const nsIID& iid, void* *result);
  80.  
  81.  
  82.     /**
  83.      * Methods called by nsCacheSession
  84.      */
  85.     static nsresult  OpenCacheEntry(nsCacheSession *           session,
  86.                                     const nsACString &         key,
  87.                                     nsCacheAccessMode          accessRequested,
  88.                                     PRBool                     blockingMode,
  89.                                     nsICacheListener *         listener,
  90.                                     nsICacheEntryDescriptor ** result);
  91.  
  92.     static nsresult  EvictEntriesForSession(nsCacheSession *   session);
  93.  
  94.     static nsresult  IsStorageEnabledForPolicy(nsCacheStoragePolicy  storagePolicy,
  95.                                                PRBool *              result);
  96.  
  97.     /**
  98.      * Methods called by nsCacheEntryDescriptor
  99.      */
  100.  
  101.     static void      CloseDescriptor(nsCacheEntryDescriptor * descriptor);
  102.  
  103.     static nsresult  GetFileForEntry(nsCacheEntry *         entry,
  104.                                      nsIFile **             result);
  105.  
  106.     static nsresult  OpenInputStreamForEntry(nsCacheEntry *     entry,
  107.                                              nsCacheAccessMode  mode,
  108.                                              PRUint32           offset,
  109.                                              nsIInputStream **  result);
  110.  
  111.     static nsresult  OpenOutputStreamForEntry(nsCacheEntry *     entry,
  112.                                               nsCacheAccessMode  mode,
  113.                                               PRUint32           offset,
  114.                                               nsIOutputStream ** result);
  115.  
  116.     static nsresult  OnDataSizeChange(nsCacheEntry * entry, PRInt32 deltaSize);
  117.  
  118.     static PRLock *  ServiceLock();
  119.     
  120.     static nsresult  SetCacheElement(nsCacheEntry * entry, nsISupports * element);
  121.  
  122.     static nsresult  ValidateEntry(nsCacheEntry * entry);
  123.  
  124.  
  125.     /**
  126.      * Methods called by any cache classes
  127.      */
  128.  
  129.     static
  130.     nsCacheService * GlobalInstance()   { return gService; }
  131.     
  132.     static nsresult  DoomEntry(nsCacheEntry * entry);
  133.  
  134.     static void      ProxyObjectRelease(nsISupports * object, PRThread * thread);
  135.  
  136.     static PRBool    IsStorageEnabledForPolicy_Locked(nsCacheStoragePolicy policy);
  137.  
  138.     /**
  139.      * Methods called by nsCacheProfilePrefObserver
  140.      */
  141.     static void      OnProfileShutdown(PRBool cleanse);
  142.     static void      OnProfileChanged();
  143.  
  144.     static void      SetDiskCacheEnabled(PRBool  enabled);
  145.     static void      SetDiskCacheCapacity(PRInt32  capacity);
  146.  
  147.     static void      SetMemoryCacheEnabled(PRBool  enabled);
  148.     static void      SetMemoryCacheCapacity(PRInt32  capacity);
  149.  
  150.     nsresult         Init();
  151.     void             Shutdown();
  152. private:
  153.  
  154.     /**
  155.      * Internal Methods
  156.      */
  157.  
  158.     nsresult         CreateDiskDevice();
  159.     nsresult         CreateMemoryDevice();
  160.  
  161.     nsresult         CreateRequest(nsCacheSession *   session,
  162.                                    const nsACString & clientKey,
  163.                                    nsCacheAccessMode  accessRequested,
  164.                                    PRBool             blockingMode,
  165.                                    nsICacheListener * listener,
  166.                                    nsCacheRequest **  request);
  167.  
  168.     nsresult         DoomEntry_Internal(nsCacheEntry * entry);
  169.  
  170.     nsresult         EvictEntriesForClient(const char *          clientID,
  171.                                            nsCacheStoragePolicy  storagePolicy);
  172.  
  173.     nsresult         NotifyListener(nsCacheRequest *          request,
  174.                                     nsICacheEntryDescriptor * descriptor,
  175.                                     nsCacheAccessMode         accessGranted,
  176.                                     nsresult                  error);
  177.  
  178.     nsresult         ActivateEntry(nsCacheRequest * request, nsCacheEntry ** entry);
  179.  
  180.     nsCacheDevice *  EnsureEntryHasDevice(nsCacheEntry * entry);
  181.  
  182.     nsCacheEntry *   SearchCacheDevices(nsCString * key, nsCacheStoragePolicy policy);
  183.  
  184.     void             DeactivateEntry(nsCacheEntry * entry);
  185.  
  186.     nsresult         ProcessRequest(nsCacheRequest *           request,
  187.                                     PRBool                     calledFromOpenCacheEntry,
  188.                                     nsICacheEntryDescriptor ** result);
  189.  
  190.     nsresult         ProcessPendingRequests(nsCacheEntry * entry);
  191.  
  192.     void             ClearPendingRequests(nsCacheEntry * entry);
  193.     void             ClearDoomList(void);
  194.     void             ClearActiveEntries(void);
  195.     void             DoomActiveEntries(void);
  196.  
  197.     PRInt32         CacheMemoryAvailable();
  198.  
  199.     static
  200.     PLDHashOperator PR_CALLBACK  DeactivateAndClearEntry(PLDHashTable *    table,
  201.                                                          PLDHashEntryHdr * hdr,
  202.                                                          PRUint32          number,
  203.                                                          void *            arg);
  204.     static
  205.     PLDHashOperator PR_CALLBACK  RemoveActiveEntry(PLDHashTable *    table,
  206.                                                    PLDHashEntryHdr * hdr,
  207.                                                    PRUint32          number,
  208.                                                    void *            arg);
  209. #if defined(PR_LOGGING)
  210.     void LogCacheStatistics();
  211. #endif
  212.  
  213.     /**
  214.      *  Data Members
  215.      */
  216.  
  217.     static nsCacheService *         gService;  // there can be only one...
  218.     nsCOMPtr<nsIEventQueueService>  mEventQService;
  219.     nsCOMPtr<nsIProxyObjectManager> mProxyObjectManager;
  220.     
  221.     nsCacheProfilePrefObserver *    mObserver;
  222.     
  223.     PRLock *                        mCacheServiceLock;
  224.     
  225.     PRBool                          mInitialized;
  226.     
  227.     PRBool                          mEnableMemoryDevice;
  228.     PRBool                          mEnableDiskDevice;
  229.  
  230.     nsMemoryCacheDevice *           mMemoryDevice;
  231.     nsDiskCacheDevice *             mDiskDevice;
  232.  
  233.     nsCacheEntryHashTable           mActiveEntries;
  234.     PRCList                         mDoomedEntries;
  235.  
  236.     // stats
  237.     
  238.     PRUint32                        mTotalEntries;
  239.     PRUint32                        mCacheHits;
  240.     PRUint32                        mCacheMisses;
  241.     PRUint32                        mMaxKeyLength;
  242.     PRUint32                        mMaxDataSize;
  243.     PRUint32                        mMaxMetaSize;
  244.  
  245.     // Unexpected error totals
  246.     PRUint32                        mDeactivateFailures;
  247.     PRUint32                        mDeactivatedUnboundEntries;
  248. };
  249.  
  250.  
  251. #endif // _nsCacheService_h_
  252.